﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


// Lots of stuff needs to be done here but not worrying about it right now.
// I will let someone more eloquent than myself handle it or get to it later.
namespace SharpMUSH
{
    static public class Error
    {
        static string corePath = "log/core.log";
        static StreamWriter CoreWriter;
        static string timeFormat = "MMM-d-y:HH:mm:ss";

        static public void Core(string message)
        {
            if (CoreWriter == null)
            {
                if (!File.Exists(Convert.SafePath(corePath)))
                {
                    try
                    {
                        if (!Directory.Exists(Path.DirectorySeparatorChar + "log"))
                        {

                            Directory.CreateDirectory("log");
                        }
                        File.Create(Convert.SafePath(corePath));
                        
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("ERROR: Could not create core log file!");
                        Console.WriteLine("  --> {0}", e.ToString());

                    }
                }
                else
                {
                    CoreWriter = File.AppendText(Convert.SafePath(corePath));
                    CoreWriter.WriteLine("-----------------------------------------");
                    CoreWriter.WriteLine("INIT: {0}", System.DateTime.Now.ToString());
                    CoreWriter.Flush();

                }

            }

            CoreWriter.WriteLine("{0}: {1}", DateTime.Now.ToString(timeFormat), message);
            CoreWriter.Flush();
#if (DEBUG)
            Console.WriteLine("CORE: {0}", message);
#endif

        }
            
    }
}
